package com.transport.analysis.traffic;

import org.apache.hadoop.io.WritableComparable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class RouteStopPairWritable implements WritableComparable<RouteStopPairWritable> {
    private int routeId;
    private String stopId;

    public RouteStopPairWritable() {
    }

    public RouteStopPairWritable(int routeId, String stopId) {
        this.routeId = routeId;
        this.stopId = stopId;
    }

    public int getRouteId() {
        return routeId;
    }

    public void setRouteId(int routeId) {
        this.routeId = routeId;
    }

    public String getStopId() {
        return stopId;
    }

    public void setStopId(String stopId) {
        this.stopId = stopId;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(routeId);
        out.writeUTF(stopId);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        routeId = in.readInt();
        stopId = in.readUTF();
    }

    @Override
    public int compareTo(RouteStopPairWritable other) {
        int cmp = Integer.compare(this.routeId, other.routeId);
        if (cmp != 0) {
            return cmp;
        }
        return this.stopId.compareTo(other.stopId);
    }

    @Override
    public int hashCode() {
        return String.valueOf(routeId).hashCode() * 163 + stopId.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        RouteStopPairWritable that = (RouteStopPairWritable) o;
        return routeId == that.routeId && stopId.equals(that.stopId);
    }

    @Override
    public String toString() {
        return routeId + "\t" + stopId;
    }
}